<?php
/**
 * Created by PhpStorm.
 * User: Dave
 * Date: 2018/7/4
 * Time: 10:14
 */

use Biz\service\ShopMall as sShopMall;
use Biz\tools\GoodsExposureLog;
use Doraemon\tools\ActionLog;

/**
 * @deprecated
 */
class GoodsListAction extends ActionPlugin
{
    const USER_LEVEL = self::LEVEL_NOTHING;
    const PAGE_SIZE = 20;

    public function main()
    {

        $actionLogMap = [
            'default',
            'new',
            'price_asc',
            'price_desc',
        ];

        $params = $this->getRequest()->getQuery('params', '{}');
        $page = $this->getRequest()->getQuery('page', 1);
        $sortType = $this->getRequest()->getQuery('sort_type', 0);
        $provinceId = $this->getRequest()->getQuery('province_id', 1);
        $cityId = $this->getRequest()->getQuery('city_id', 0);
        $params = json_decode($params, true);
        $page = $page < 1 ? 1 : $page;

        $areaCode = $cityId ? $cityId : $provinceId;
        if (!empty($params['tag'])) {

            $data = sShopMall::RecommendByTag($this->uid, $params, $page, self::PAGE_SIZE, $sortType, $areaCode);

        } elseif (!empty($params['keyword'])) {

            $data = sShopMall::RecommendByKeyWord($this->uid, $params['keyword'], $page, self::PAGE_SIZE, $areaCode);

        }
        ActionLog::log($this->uid, [
            'params' => $params,
            'page' => $page,
            'sort_type' => $actionLogMap[$sortType]
        ], ActionLog::BIZ_MALL_GOODS_LIST);
        $data = $data ?: (object)$data;
        $this->setSuccess($data);
        GoodsExposureLog::addLog($this->getRequest(), $data, isset($params['tag']) ? $params['tag'] : $params['keyword']);
    }
}